package com.cat.model.biz.logic.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.alonew.db.dao.TxCommonDAO;
import com.cat.model.biz.logic.PersonLogic;
import com.cat.model.common.model.common.Person;
import com.cat.model.dao.common.PlmCommDAO;
import com.cat.model.dao.common.impl.PlmCommDAOImpl;
import com.cat.model.dao.mapper.PersonMapper;

@Service("personLogic")
public class PersonLogicImpl implements PersonLogic {

	@Autowired
	private TxCommonDAO commonDAO;
	
	@Autowired
	private PersonMapper personMapper;
	
	@Autowired
	private PlmCommDAO plmCommDAO;
	
	@Override
	public Person insert(String name, int age, String sex, String password) throws Exception {
		Person person = new Person();
		person.setAge(age);
		person.setName(name);
		person.setPassword(password);
		person.setSex(sex);
		commonDAO.insert(person);
	    
		throw new Exception("");
//		return person;
	}

	@Override
	public void update(Person person, String password) {
		person.setPassword(password);
		commonDAO.updateById(person, "password");
	}

	@Override
	public void delete(int id) {
		Person person = new Person();
		person.setId(id);
		commonDAO.deleteById(person);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Person> list() {
		return (List<Person>)plmCommDAO.query("manager.searchPersonList", new HashMap<String, Object>());
	}
	
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		ApplicationContext  applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		PersonLogic personLogic = (PersonLogic) applicationContext.getBean("personLogic");
		try {
			System.out.println(personLogic.list());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
